package com.qdu.spring.blog.config;

import com.qdu.spring.blog.interceptor.IsLoginInterceptor;
import com.qdu.spring.blog.util.MyConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web拦截器配置配置
 *
 */
@Configuration//表明此类是一个适配器
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private IsLoginInterceptor isLoginInterceptor;
    /**
     * 配置拦截器，拦截器按照顺序执行
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        //1.是否登录拦截器
        InterceptorRegistration loginInterceptor = registry.addInterceptor(this.isLoginInterceptor);
        //需要拦截的路径
        loginInterceptor.addPathPatterns(MyConstant.ADD_PATHS);
        //需要放行的路径
        loginInterceptor.excludePathPatterns(MyConstant.EXCLUDE_PATHS);

        //2.权限拦截器
//        InterceptorRegistration permissionInterceptor = registry.addInterceptor(this.permissionInterceptor);
//        permissionInterceptor.addPathPatterns(MyConstant.ADD_PATHS);
//        permissionInterceptor.excludePathPatterns(MyConstant.EXCLUDE_PATHS);
    }
}
